library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.3     ✓ purrr   0.3.4
## ✓ tibble  3.1.1     ✓ dplyr   1.0.5
## ✓ tidyr   1.1.3     ✓ stringr 1.4.0
## ✓ readr   1.4.0     ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(tidytuesdayR)
library(lubridate)
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
cricket_list <- tidytuesdayR::tt_load('2021-11-30')
## Only 10 Github queries remaining until 2021-12-07 12:53:37 pm ACDT.
## Only 10 Github queries remaining until 2021-12-07 12:53:37 pm ACDT.
## Only 10 Github queries remaining until 2021-12-07 12:53:37 pm ACDT.
## Only 10 Github queries remaining until 2021-12-07 12:53:37 pm ACDT.
## Only 10 Github queries remaining until 2021-12-07 12:53:36 pm ACDT.
## --- Compiling #TidyTuesday Information for 2021-11-30 ----
## Only 9 Github queries remaining until 2021-12-07 12:53:36 pm ACDT.
## --- There is 1 file available ---
## Only 8 Github queries remaining until 2021-12-07 12:53:36 pm ACDT.
## --- Starting Download ---
## Only 8 Github queries remaining until 2021-12-07 12:53:36 pm ACDT.
##  Downloading file 1 of 1: `matches.csv`
## Only 7 Github queries remaining until 2021-12-07 12:53:36 pm ACDT.
## --- Download complete ---
cricket <- cricket_list$matches

  
who_list <- tidytuesdayR::tt_load('2021-11-23')
## Only 6 Github queries remaining until 2021-12-07 12:53:36 pm ACDT.
## Only 6 Github queries remaining until 2021-12-07 12:53:36 pm ACDT.
## --- Compiling #TidyTuesday Information for 2021-11-23 ----
## Only 6 Github queries remaining until 2021-12-07 12:53:36 pm ACDT.
## --- There are 4 files available ---
## Only 5 Github queries remaining until 2021-12-07 12:53:36 pm ACDT.
## --- Starting Download ---
## Only 5 Github queries remaining until 2021-12-07 12:53:36 pm ACDT.
##  Downloading file 1 of 4: `writers.csv`
## Only 4 Github queries remaining until 2021-12-07 12:53:36 pm ACDT.
##  Downloading file 2 of 4: `directors.csv`
## Only 3 Github queries remaining until 2021-12-07 12:53:36 pm ACDT.
##  Downloading file 3 of 4: `episodes.csv`
## Only 2 Github queries remaining until 2021-12-07 12:53:36 pm ACDT.
##  Downloading file 4 of 4: `imdb.csv`
## Only 1 Github queries remaining until 2021-12-07 12:53:36 pm ACDT.
## --- Download complete ---
who_ep <- who_list$episodes
who_IMDB <- who_list$imdb

Cricket exploration

A One Day International (ODI) is a form of limited overs cricket, played between two teams with international status, in which each team faces a fixed number of overs, currently 50, with the game lasting up to 9 hours. The Cricket World Cup, generally held every four years, is played in this format. One Day International matches are also called Limited Overs Internationals (LOI), although this generic term may also refer to Twenty20 International matches. They are major matches and considered the highest standard of List A, limited-overs competition.

The Cricket World Cup (officially known as ICC Men’s Cricket World Cup)[2] is the international championship of One Day International (ODI) cricket. The event is organised by the sport’s governing body, the International Cricket Council (ICC), every four years, with preliminary qualification rounds leading up to a finals tournament. The tournament is one of the world’s most viewed sporting events and is considered the “flagship event of the international cricket calendar” by the ICC

What are we working with?

summary(cricket)
##    match_id            team1              team2            score_team1   
##  Length:1237        Length:1237        Length:1237        Min.   : 35.0  
##  Class :character   Class :character   Class :character   1st Qu.:198.0  
##  Mode  :character   Mode  :character   Mode  :character   Median :237.0  
##                                                           Mean   :233.2  
##                                                           3rd Qu.:272.0  
##                                                           Max.   :398.0  
##                                                                          
##   score_team2    wickets_team1    wickets_team2    team1_away_or_home
##  Min.   :  8.0   Min.   : 2.000   Min.   : 0.000   Length:1237       
##  1st Qu.:165.0   1st Qu.: 6.000   1st Qu.: 4.000   Class :character  
##  Median :203.0   Median : 8.000   Median : 7.000   Mode  :character  
##  Mean   :200.3   Mean   : 7.743   Mean   : 6.763                     
##  3rd Qu.:237.0   3rd Qu.:10.000   3rd Qu.:10.000                     
##  Max.   :344.0   Max.   :10.000   Max.   :10.000                     
##                                                                      
##  team2_home_away       winner              margin       margin_type       
##  Length:1237        Length:1237        Min.   :  1.00   Length:1237       
##  Class :character   Class :character   1st Qu.:  6.00   Class :character  
##  Mode  :character   Mode  :character   Median :  9.00   Mode  :character  
##                                        Mean   : 35.52                     
##                                        3rd Qu.: 52.00                     
##                                        Max.   :256.00                     
##                                        NA's   :16                         
##  time_of_day           series          player_of_match    player_of_match_team
##  Length:1237        Length:1237        Length:1237        Length:1237         
##  Class :character   Class :character   Class :character   Class :character    
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character    
##                                                                               
##                                                                               
##                                                                               
##                                                                               
##     venue               toss           toss_decision      ball_remaining    
##  Length:1237        Length:1237        Length:1237        Length:1237       
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##     ground          ground_city        ground_country      match_date       
##  Length:1237        Length:1237        Length:1237        Length:1237       
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
## 
view(cricket)

The information about the data set says that the ICC World Cup is held every 4 years. Does this mean that our data set only includes dates every 4 years?

unique(cricket$match_date)
##    [1] "Jan 1, 1996"     "Jan 3, 1996"     "Jan 5, 1996"     "Jan 7, 1996"    
##    [5] "Jan 9, 1996"     "Jan 11, 1996"    "Jan 12, 1996"    "Jan 13, 1996"   
##    [9] "Jan 14, 1996"    "Jan 16, 1996"    "Jan 17, 1996"    "Jan 19, 1996"   
##   [13] "Jan 21, 1996"    "Jan 28, 1996"    "Jan 31, 1996"    "Feb 3, 1996"    
##   [17] "Feb 14, 1996"    "Feb 16, 1996"    "Feb 17, 1996"    "Feb 18, 1996"   
##   [21] "Feb 20, 1996"    "Feb 21, 1996"    "Feb 22, 1996"    "Feb 23, 1996"   
##   [25] "Feb 24, 1996"    "Feb 25, 1996"    "Feb 26, 1996"    "Feb 27, 1996"   
##   [29] "Feb 29, 1996"    "Mar 1, 1996"     "Mar 2, 1996"     "Mar 3, 1996"    
##   [33] "Mar 4, 1996"     "Mar 5, 1996"     "Mar 6, 1996"     "Mar 9, 1996"    
##   [37] "Mar 11, 1996"    "Mar 13, 1996"    "Mar 17, 1996"    "Mar 26, 1996"   
##   [41] "Mar 29, 1996"    "Mar 30, 1996"    "Apr 2, 1996"     "Apr 3, 1996"    
##   [45] "Apr 5, 1996"     "Apr 6, 1996"     "Apr 7, 1996"     "Apr 12, 1996"   
##   [49] "Apr 13, 1996"    "Apr 14, 1996"    "Apr 15, 1996"    "Apr 16, 1996"   
##   [53] "Apr 17, 1996"    "Apr 19, 1996"    "May 23-24, 1996" "May 25, 1996"   
##   [57] "May 26-27, 1996" "Aug 26, 1996"    "Aug 28, 1996"    "Aug 29, 1996"   
##   [61] "Aug 30, 1996"    "Aug 31, 1996"    "Sep 1, 1996"     "Sep 3, 1996"    
##   [65] "Sep 6, 1996"     "Sep 7, 1996"     "Sep 16, 1996"    "Sep 17, 1996"   
##   [69] "Sep 18, 1996"    "Sep 21, 1996"    "Sep 23, 1996"    "Sep 28, 1996"   
##   [73] "Sep 29, 1996"    "Oct 1, 1996"     "Oct 2, 1996"     "Oct 3, 1996"    
##   [77] "Oct 4, 1996"     "Oct 6, 1996"     "Oct 17, 1996"    "Oct 19, 1996"   
##   [81] "Oct 21, 1996"    "Oct 23, 1996"    "Oct 25, 1996"    "Oct 29, 1996"   
##   [85] "Oct 30, 1996"    "Nov 1, 1996"     "Nov 3, 1996"     "Nov 6, 1996"    
##   [89] "Nov 7, 1996"     "Nov 8, 1996"     "Nov 10, 1996"    "Nov 11, 1996"   
##   [93] "Nov 12, 1996"    "Nov 13, 1996"    "Nov 15, 1996"    "Dec 4, 1996"    
##   [97] "Dec 6, 1996"     "Dec 8, 1996"     "Dec 14, 1996"    "Dec 15, 1996"   
##  [101] "Dec 17, 1996"    "Jan 1, 1997"     "Jan 3, 1997"     "Jan 5, 1997"    
##  [105] "Jan 7, 1997"     "Jan 10, 1997"    "Jan 12, 1997"    "Jan 14, 1997"   
##  [109] "Jan 16, 1997"    "Jan 23, 1997"    "Jan 25, 1997"    "Jan 27, 1997"   
##  [113] "Jan 29, 1997"    "Jan 31, 1997"    "Feb 2, 1997"     "Feb 4, 1997"    
##  [117] "Feb 7, 1997"     "Feb 9, 1997"     "Feb 13, 1997"    "Feb 15, 1997"   
##  [121] "Feb 20, 1997"    "Feb 23, 1997"    "Feb 26, 1997"    "Mar 2, 1997"    
##  [125] "Mar 4, 1997"     "Mar 25, 1997"    "Mar 27, 1997"    "Mar 29, 1997"   
##  [129] "Mar 31, 1997"    "Apr 2, 1997"     "Apr 3, 1997"     "Apr 4, 1997"    
##  [133] "Apr 5, 1997"     "Apr 6, 1997"     "Apr 7, 1997"     "Apr 8, 1997"    
##  [137] "Apr 9, 1997"     "Apr 10, 1997"    "Apr 11, 1997"    "Apr 13, 1997"   
##  [141] "Apr 26, 1997"    "Apr 27, 1997"    "Apr 30, 1997"    "May 3, 1997"    
##  [145] "May 9, 1997"     "May 12, 1997"    "May 14, 1997"    "May 17, 1997"   
##  [149] "May 20, 1997"    "May 21, 1997"    "May 22, 1997"    "May 24, 1997"   
##  [153] "May 25, 1997"    "May 27, 1997"    "Jun 6, 1997"     "Jul 14, 1997"   
##  [157] "Jul 16, 1997"    "Jul 18, 1997"    "Jul 22, 1997"    "Jul 24, 1997"   
##  [161] "Jul 26, 1997"    "Aug 17, 1997"    "Aug 20, 1997"    "Aug 24, 1997"   
##  [165] "Sep 13, 1997"    "Sep 14, 1997"    "Sep 18, 1997"    "Sep 20, 1997"   
##  [169] "Sep 21, 1997"    "Sep 28, 1997"    "Sep 30, 1997"    "Oct 1, 1997"    
##  [173] "Oct 2, 1997"     "Oct 4, 1997"     "Oct 5, 1997"     "Oct 10, 1997"   
##  [177] "Oct 11, 1997"    "Oct 12, 1997"    "Oct 14, 1997"    "Oct 15, 1997"   
##  [181] "Oct 16, 1997"    "Oct 18, 1997"    "Oct 19, 1997"    "Nov 1, 1997"    
##  [185] "Nov 2, 1997"     "Nov 3, 1997"     "Nov 4, 1997"     "Nov 5, 1997"    
##  [189] "Nov 6, 1997"     "Nov 8, 1997"     "Dec 4, 1997"     "Dec 6, 1997"    
##  [193] "Dec 7, 1997"     "Dec 9, 1997"     "Dec 11, 1997"    "Dec 12, 1997"   
##  [197] "Dec 13, 1997"    "Dec 14, 1997"    "Dec 15, 1997"    "Dec 16, 1997"   
##  [201] "Dec 17, 1997"    "Dec 19, 1997"    "Dec 22, 1997"    "Dec 28, 1997"   
##  [205] "Jan 9, 1998"     "Jan 10, 1998"    "Jan 11, 1998"    "Jan 12, 1998"   
##  [209] "Jan 14, 1998"    "Jan 16, 1998"    "Jan 18, 1998"    "Jan 21, 1998"   
##  [213] "Jan 22, 1998"    "Jan 23, 1998"    "Jan 24, 1998"    "Jan 26, 1998"   
##  [217] "Jan 27, 1998"    "Feb 4, 1998"     "Feb 6, 1998"     "Feb 8, 1998"    
##  [221] "Feb 10, 1998"    "Feb 12, 1998"    "Feb 14, 1998"    "Mar 4, 1998"    
##  [225] "Mar 6, 1998"     "Mar 8, 1998"     "Mar 28, 1998"    "Mar 29, 1998"   
##  [229] "Apr 1, 1998"     "Apr 3, 1998"     "Apr 4, 1998"     "Apr 5, 1998"    
##  [233] "Apr 7, 1998"     "Apr 8, 1998"     "Apr 9, 1998"     "Apr 11, 1998"   
##  [237] "Apr 13, 1998"    "Apr 14, 1998"    "Apr 15, 1998"    "Apr 17, 1998"   
##  [241] "Apr 18, 1998"    "Apr 19, 1998"    "Apr 20, 1998"    "Apr 21, 1998"   
##  [245] "Apr 22, 1998"    "Apr 23, 1998"    "Apr 24, 1998"    "May 14, 1998"   
##  [249] "May 17, 1998"    "May 20, 1998"    "May 21, 1998"    "May 23, 1998"   
##  [253] "May 24, 1998"    "May 25, 1998"    "May 28, 1998"    "May 31, 1998"   
##  [257] "Jun 19, 1998"    "Jun 21, 1998"    "Jul 1, 1998"     "Jul 5, 1998"    
##  [261] "Jul 7, 1998"     "Aug 14, 1998"    "Aug 16, 1998"    "Aug 18, 1998"   
##  [265] "Aug 20, 1998"    "Sep 12, 1998"    "Sep 13, 1998"    "Sep 16, 1998"   
##  [269] "Sep 19, 1998"    "Sep 20, 1998"    "Sep 26, 1998"    "Sep 27, 1998"   
##  [273] "Sep 30, 1998"    "Oct 24, 1998"    "Oct 25, 1998"    "Oct 26, 1998"   
##  [277] "Oct 28, 1998"    "Oct 29, 1998"    "Oct 30, 1998"    "Oct 31, 1998"   
##  [281] "Nov 1, 1998"     "Nov 6, 1998"     "Nov 7, 1998"     "Nov 8, 1998"    
##  [285] "Nov 9, 1998"     "Nov 10, 1998"    "Nov 11, 1998"    "Nov 13, 1998"   
##  [289] "Nov 20, 1998"    "Nov 22, 1998"    "Nov 24, 1998"    "Jan 9, 1999"    
##  [293] "Jan 10, 1999"    "Jan 11, 1999"    "Jan 12, 1999"    "Jan 13, 1999"   
##  [297] "Jan 15, 1999"    "Jan 16, 1999"    "Jan 17, 1999"    "Jan 19, 1999"   
##  [301] "Jan 21, 1999"    "Jan 22, 1999"    "Jan 23, 1999"    "Jan 24, 1999"   
##  [305] "Jan 26, 1999"    "Jan 27, 1999"    "Jan 29, 1999"    "Jan 30, 1999"   
##  [309] "Jan 31, 1999"    "Feb 2, 1999"     "Feb 3, 1999"     "Feb 5, 1999"    
##  [313] "Feb 7, 1999"     "Feb 10, 1999"    "Feb 13, 1999"    "Feb 14, 1999"   
##  [317] "Feb 17, 1999"    "Feb 20, 1999"    "Mar 16, 1999"    "Mar 19, 1999"   
##  [321] "Mar 20, 1999"    "Mar 21, 1999"    "Mar 22, 1999"    "Mar 23, 1999"   
##  [325] "Mar 24, 1999"    "Mar 25, 1999"    "Mar 26, 1999"    "Mar 27, 1999"   
##  [329] "Mar 30, 1999"    "Apr 1, 1999"     "Apr 4, 1999"     "Apr 7, 1999"    
##  [333] "Apr 8, 1999"     "Apr 9, 1999"     "Apr 11, 1999"    "Apr 12, 1999"   
##  [337] "Apr 13, 1999"    "Apr 14, 1999"    "Apr 16, 1999"    "Apr 17, 1999"   
##  [341] "Apr 18, 1999"    "Apr 21, 1999"    "Apr 24, 1999"    "Apr 25, 1999"   
##  [345] "May 14, 1999"    "May 15, 1999"    "May 16, 1999"    "May 17, 1999"   
##  [349] "May 18, 1999"    "May 19, 1999"    "May 20, 1999"    "May 21, 1999"   
##  [353] "May 22, 1999"    "May 23, 1999"    "May 24, 1999"    "May 25, 1999"   
##  [357] "May 26, 1999"    "May 27, 1999"    "May 28, 1999"    "May 29-30, 1999"
##  [361] "May 29, 1999"    "May 30, 1999"    "May 31, 1999"    "Jun 4, 1999"    
##  [365] "Jun 5, 1999"     "Jun 8, 1999"     "Jun 9, 1999"     "Jun 10, 1999"   
##  [369] "Jun 11, 1999"    "Jun 12, 1999"    "Jun 13, 1999"    "Jun 16, 1999"   
##  [373] "Jun 17, 1999"    "Jun 20, 1999"    "Aug 22, 1999"    "Aug 23, 1999"   
##  [377] "Aug 25, 1999"    "Aug 26, 1999"    "Aug 28, 1999"    "Aug 29, 1999"   
##  [381] "Aug 31, 1999"    "Sep 2, 1999"     "Sep 4, 1999"     "Sep 5, 1999"    
##  [385] "Sep 8, 1999"     "Sep 11, 1999"    "Sep 12, 1999"    "Sep 14, 1999"   
##  [389] "Sep 16, 1999"    "Sep 18, 1999"    "Sep 19, 1999"    "Sep 25, 1999"   
##  [393] "Sep 26, 1999"    "Sep 28, 1999"    "Sep 29, 1999"    "Sep 30, 1999"   
##  [397] "Oct 1, 1999"     "Oct 3, 1999"     "Oct 8, 1999"     "Oct 9, 1999"    
##  [401] "Oct 13, 1999"    "Oct 14, 1999"    "Oct 15, 1999"    "Oct 17, 1999"   
##  [405] "Oct 18, 1999"    "Oct 19, 1999"    "Oct 21, 1999"    "Oct 22, 1999"   
##  [409] "Oct 23, 1999"    "Oct 24, 1999"    "Nov 5, 1999"     "Nov 8, 1999"    
##  [413] "Nov 11, 1999"    "Nov 14, 1999"    "Nov 17, 1999"    "Dec 12, 1999"   
##  [417] "Dec 15, 1999"    "Dec 18, 1999"    "Dec 19, 1999"    "Jan 2, 2000"    
##  [421] "Jan 4, 2000"     "Jan 6, 2000"     "Jan 8-9, 2000"   "Jan 9, 2000"    
##  [425] "Jan 10, 2000"    "Jan 11, 2000"    "Jan 12, 2000"    "Jan 14, 2000"   
##  [429] "Jan 16, 2000"    "Jan 19, 2000"    "Jan 21, 2000"    "Jan 23, 2000"   
##  [433] "Jan 25, 2000"    "Jan 26, 2000"    "Jan 28, 2000"    "Jan 30, 2000"   
##  [437] "Feb 2, 2000"     "Feb 4, 2000"     "Feb 6, 2000"     "Feb 13, 2000"   
##  [441] "Feb 16, 2000"    "Feb 18, 2000"    "Feb 19, 2000"    "Feb 20, 2000"   
##  [445] "Feb 23, 2000"    "Feb 26, 2000"    "Mar 1, 2000"     "Mar 3, 2000"    
##  [449] "Mar 9, 2000"     "Mar 12, 2000"    "Mar 15, 2000"    "Mar 17, 2000"   
##  [453] "Mar 19, 2000"    "Mar 22, 2000"    "Mar 23, 2000"    "Mar 24, 2000"   
##  [457] "Mar 26, 2000"    "Mar 27, 2000"    "Mar 28, 2000"    "Mar 31, 2000"   
##  [461] "Apr 1, 2000"     "Apr 2, 2000"     "Apr 5, 2000"     "Apr 12, 2000"   
##  [465] "Apr 14, 2000"    "Apr 15, 2000"    "Apr 16, 2000"    "Apr 19, 2000"   
##  [469] "Apr 22, 2000"    "Apr 23, 2000"    "May 29, 2000"    "May 30-31, 2000"
##  [473] "Jun 1, 2000"     "Jun 2, 2000"     "Jun 3, 2000"     "Jun 5, 2000"    
##  [477] "Jun 7, 2000"     "Jul 5, 2000"     "Jul 6, 2000"     "Jul 8, 2000"    
##  [481] "Jul 9, 2000"     "Jul 11, 2000"    "Jul 12, 2000"    "Jul 13, 2000"   
##  [485] "Jul 14, 2000"    "Jul 15, 2000"    "Jul 16, 2000"    "Jul 18, 2000"   
##  [489] "Jul 20, 2000"    "Jul 22, 2000"    "Aug 16, 2000"    "Aug 18, 2000"   
##  [493] "Aug 20, 2000"    "Aug 23, 2000"    "Aug 25, 2000"    "Aug 27, 2000"   
##  [497] "Sep 27, 2000"    "Sep 30, 2000"    "Oct 1, 2000"     "Oct 3, 2000"    
##  [501] "Oct 4, 2000"     "Oct 5, 2000"     "Oct 7, 2000"     "Oct 8, 2000"    
##  [505] "Oct 9, 2000"     "Oct 10, 2000"    "Oct 11, 2000"    "Oct 13, 2000"   
##  [509] "Oct 15, 2000"    "Oct 20, 2000"    "Oct 21, 2000"    "Oct 22, 2000"   
##  [513] "Oct 24, 2000"    "Oct 25, 2000"    "Oct 26, 2000"    "Oct 27, 2000"   
##  [517] "Oct 28, 2000"    "Oct 29, 2000"    "Oct 30, 2000"    "Nov 1, 2000"    
##  [521] "Nov 4, 2000"     "Dec 2, 2000"     "Dec 5, 2000"     "Dec 8, 2000"    
##  [525] "Dec 11, 2000"    "Dec 14, 2000"    "Dec 15, 2000"    "Dec 17, 2000"   
##  [529] "Jan 2, 2001"     "Jan 4, 2001"     "Jan 7, 2001"     "Jan 9, 2001"    
##  [533] "Jan 11, 2001"    "Jan 13, 2001"    "Jan 14, 2001"    "Jan 17, 2001"   
##  [537] "Jan 21, 2001"    "Jan 23, 2001"    "Jan 25, 2001"    "Jan 26, 2001"   
##  [541] "Jan 28, 2001"    "Jan 30, 2001"    "Jan 31, 2001"    "Feb 2, 2001"    
##  [545] "Feb 3, 2001"     "Feb 4, 2001"     "Feb 6, 2001"     "Feb 7, 2001"    
##  [549] "Feb 8, 2001"     "Feb 9, 2001"     "Feb 11, 2001"    "Feb 17-18, 2001"
##  [553] "Feb 20, 2001"    "Feb 22, 2001"    "Feb 25, 2001"    "Feb 28, 2001"   
##  [557] "Mar 23, 2001"    "Mar 25, 2001"    "Mar 27, 2001"    "Mar 28, 2001"   
##  [561] "Mar 31, 2001"    "Apr 3, 2001"     "Apr 6, 2001"     "Apr 7, 2001"    
##  [565] "Apr 8, 2001"     "Apr 10, 2001"    "Apr 11, 2001"    "Apr 12, 2001"   
##  [569] "Apr 13, 2001"    "Apr 15, 2001"    "Apr 17, 2001"    "Apr 20, 2001"   
##  [573] "Apr 28, 2001"    "May 2, 2001"     "May 5, 2001"     "May 6, 2001"    
##  [577] "May 9, 2001"     "May 12, 2001"    "May 16, 2001"    "Jun 7, 2001"    
##  [581] "Jun 9, 2001"     "Jun 10, 2001"    "Jun 12, 2001"    "Jun 14, 2001"   
##  [585] "Jun 17, 2001"    "Jun 19, 2001"    "Jun 21, 2001"    "Jun 23, 2001"   
##  [589] "Jun 24, 2001"    "Jun 27, 2001"    "Jun 30, 2001"    "Jul 1, 2001"    
##  [593] "Jul 4, 2001"     "Jul 7, 2001"     "Jul 18, 2001"    "Jul 20, 2001"   
##  [597] "Jul 22, 2001"    "Jul 25, 2001"    "Jul 26, 2001"    "Jul 28, 2001"   
##  [601] "Jul 31, 2001"    "Aug 1, 2001"     "Aug 2, 2001"     "Aug 5, 2001"    
##  [605] "Aug 15, 2001"    "Aug 18, 2001"    "Aug 19, 2001"    "Sep 23, 2001"   
##  [609] "Sep 29, 2001"    "Sep 30, 2001"    "Oct 3, 2001"     "Oct 5, 2001"    
##  [613] "Oct 6, 2001"     "Oct 7, 2001"     "Oct 10, 2001"    "Oct 12, 2001"   
##  [617] "Oct 13, 2001"    "Oct 14, 2001"    "Oct 17, 2001"    "Oct 19, 2001"   
##  [621] "Oct 22, 2001"    "Oct 24, 2001"    "Oct 26, 2001"    "Oct 27, 2001"   
##  [625] "Oct 28, 2001"    "Oct 30, 2001"    "Oct 31, 2001"    "Nov 2, 2001"    
##  [629] "Nov 4, 2001"     "Nov 23, 2001"    "Nov 25, 2001"    "Nov 26, 2001"   
##  [633] "Dec 8, 2001"     "Dec 9, 2001"     "Dec 11, 2001"    "Dec 12, 2001"   
##  [637] "Dec 15, 2001"    "Dec 16, 2001"    "Dec 19, 2001"    "Jan 11, 2002"   
##  [641] "Jan 13, 2002"    "Jan 15, 2002"    "Jan 17, 2002"    "Jan 19, 2002"   
##  [645] "Jan 20, 2002"    "Jan 22, 2002"    "Jan 24, 2002"    "Jan 25, 2002"   
##  [649] "Jan 26, 2002"    "Jan 27, 2002"    "Jan 28, 2002"    "Jan 29, 2002"   
##  [653] "Jan 31, 2002"    "Feb 1, 2002"     "Feb 3, 2002"     "Feb 6, 2002"    
##  [657] "Feb 8, 2002"     "Feb 13, 2002"    "Feb 14, 2002"    "Feb 15, 2002"   
##  [661] "Feb 16, 2002"    "Feb 17, 2002"    "Feb 20, 2002"    "Feb 23, 2002"   
##  [665] "Feb 26, 2002"    "Mar 7, 2002"     "Mar 10, 2002"    "Mar 13, 2002"   
##  [669] "Mar 16, 2002"    "Mar 19, 2002"    "Mar 22, 2002"    "Mar 24, 2002"   
##  [673] "Mar 27, 2002"    "Mar 30, 2002"    "Apr 3, 2002"     "Apr 6, 2002"    
##  [677] "Apr 8, 2002"     "Apr 9, 2002"     "Apr 11, 2002"    "Apr 12, 2002"   
##  [681] "Apr 14, 2002"    "Apr 15, 2002"    "Apr 17, 2002"    "Apr 21, 2002"   
##  [685] "Apr 24, 2002"    "Apr 27, 2002"    "May 29, 2002"    "Jun 1, 2002"    
##  [689] "Jun 2, 2002"     "Jun 8, 2002"     "Jun 9, 2002"     "Jun 12, 2002"   
##  [693] "Jun 15, 2002"    "Jun 16, 2002"    "Jun 19, 2002"    "Jun 27, 2002"   
##  [697] "Jun 29, 2002"    "Jun 30, 2002"    "Jul 2, 2002"     "Jul 6, 2002"    
##  [701] "Jul 7, 2002"     "Jul 9, 2002"     "Jul 11, 2002"    "Jul 13, 2002"   
##  [705] "Aug 4, 2002"     "Aug 5, 2002"     "Aug 7, 2002"     "Aug 12, 2002"   
##  [709] "Aug 14, 2002"    "Aug 15, 2002"    "Aug 17, 2002"    "Aug 18, 2002"   
##  [713] "Aug 19, 2002"    "Aug 21, 2002"    "Aug 29, 2002"    "Aug 30, 2002"   
##  [717] "Sep 1, 2002"     "Sep 2, 2002"     "Sep 4, 2002"     "Sep 5, 2002"    
##  [721] "Sep 12, 2002"    "Sep 13, 2002"    "Sep 14, 2002"    "Sep 15, 2002"   
##  [725] "Sep 16, 2002"    "Sep 17, 2002"    "Sep 18, 2002"    "Sep 19, 2002"   
##  [729] "Sep 20, 2002"    "Sep 21, 2002"    "Sep 22, 2002"    "Sep 23, 2002"   
##  [733] "Sep 25, 2002"    "Sep 27, 2002"    "Oct 3, 2002"     "Oct 6, 2002"    
##  [737] "Oct 9, 2002"     "Nov 6, 2002"     "Nov 9, 2002"     "Nov 12, 2002"   
##  [741] "Nov 15, 2002"    "Nov 18, 2002"    "Nov 21, 2002"    "Nov 23, 2002"   
##  [745] "Nov 24, 2002"    "Nov 27, 2002"    "Nov 29, 2002"    "Nov 30, 2002"   
##  [749] "Dec 1, 2002"     "Dec 2, 2002"     "Dec 3, 2002"     "Dec 4, 2002"    
##  [753] "Dec 6, 2002"     "Dec 8, 2002"     "Dec 11, 2002"    "Dec 13, 2002"   
##  [757] "Dec 15, 2002"    "Dec 16, 2002"    "Dec 17, 2002"    "Dec 18, 2002"   
##  [761] "Dec 20, 2002"    "Dec 22, 2002"    "Dec 26, 2002"    "Dec 29, 2002"   
##  [765] "Jan 1, 2003"     "Jan 4, 2003"     "Jan 8, 2003"     "Jan 9, 2003"    
##  [769] "Jan 11, 2003"    "Jan 13, 2003"    "Jan 14, 2003"    "Jan 15, 2003"   
##  [773] "Jan 17, 2003"    "Jan 19, 2003"    "Jan 21, 2003"    "Jan 23, 2003"   
##  [777] "Jan 25, 2003"    "Feb 9, 2003"     "Feb 10, 2003"    "Feb 11, 2003"   
##  [781] "Feb 12, 2003"    "Feb 13, 2003"    "Feb 14, 2003"    "Feb 15, 2003"   
##  [785] "Feb 16, 2003"    "Feb 19, 2003"    "Feb 20, 2003"    "Feb 22, 2003"   
##  [789] "Feb 23, 2003"    "Feb 24, 2003"    "Feb 25, 2003"    "Feb 26, 2003"   
##  [793] "Feb 27, 2003"    "Feb 28, 2003"    "Mar 1, 2003"     "Mar 2, 2003"    
##  [797] "Mar 3, 2003"     "Mar 4, 2003"     "Mar 7, 2003"     "Mar 8, 2003"    
##  [801] "Mar 10, 2003"    "Mar 11, 2003"    "Mar 12, 2003"    "Mar 14, 2003"   
##  [805] "Mar 15, 2003"    "Mar 18, 2003"    "Mar 20, 2003"    "Mar 23, 2003"   
##  [809] "Apr 3, 2003"     "Apr 4, 2003"     "Apr 5, 2003"     "Apr 6, 2003"    
##  [813] "Apr 7, 2003"     "Apr 8, 2003"     "Apr 10, 2003"    "Apr 11, 2003"   
##  [817] "Apr 13, 2003"    "Apr 14, 2003"    "Apr 16, 2003"    "Apr 17, 2003"   
##  [821] "Apr 18, 2003"    "May 10, 2003"    "May 11, 2003"    "May 13, 2003"   
##  [825] "May 17, 2003"    "May 18, 2003"    "May 19, 2003"    "May 20, 2003"   
##  [829] "May 21, 2003"    "May 23, 2003"    "May 24, 2003"    "May 25, 2003"   
##  [833] "May 30, 2003"    "Jun 1, 2003"     "Jun 7, 2003"     "Jun 8, 2003"    
##  [837] "Jun 11, 2003"    "Jun 17, 2003"    "Jun 20, 2003"    "Jun 22, 2003"   
##  [841] "Jun 26, 2003"    "Jun 28, 2003"    "Jun 29, 2003"    "Jul 3, 2003"    
##  [845] "Jul 5, 2003"     "Jul 6, 2003"     "Jul 8, 2003"     "Jul 10, 2003"   
##  [849] "Jul 12, 2003"    "Aug 2, 2003"     "Aug 3, 2003"     "Aug 6, 2003"    
##  [853] "Sep 9, 2003"     "Sep 12, 2003"    "Sep 15, 2003"    "Sep 18, 2003"   
##  [857] "Sep 21, 2003"    "Oct 3, 2003"     "Oct 5, 2003"     "Oct 7, 2003"    
##  [861] "Oct 10, 2003"    "Oct 12, 2003"    "Oct 26, 2003"    "Oct 29, 2003"   
##  [865] "Nov 1, 2003"     "Nov 3, 2003"     "Nov 6, 2003"     "Nov 7, 2003"    
##  [869] "Nov 9, 2003"     "Nov 10, 2003"    "Nov 12, 2003"    "Nov 15, 2003"   
##  [873] "Nov 18, 2003"    "Nov 22, 2003"    "Nov 23, 2003"    "Nov 26, 2003"   
##  [877] "Nov 29, 2003"    "Nov 30, 2003"    "Dec 1, 2003"     "Dec 3, 2003"    
##  [881] "Dec 5, 2003"     "Dec 7, 2003"     "Jan 3, 2004"     "Jan 7, 2004"    
##  [885] "Jan 9, 2004"     "Jan 10, 2004"    "Jan 11, 2004"    "Jan 14, 2004"   
##  [889] "Jan 16, 2004"    "Jan 17, 2004"    "Jan 18, 2004"    "Jan 20, 2004"   
##  [893] "Jan 22, 2004"    "Jan 24, 2004"    "Jan 25, 2004"    "Jan 26, 2004"   
##  [897] "Jan 28, 2004"    "Feb 1, 2004"     "Feb 3, 2004"     "Feb 4, 2004"    
##  [901] "Feb 6, 2004"     "Feb 8, 2004"     "Feb 13, 2004"    "Feb 17, 2004"   
##  [905] "Feb 20, 2004"    "Feb 22, 2004"    "Feb 25, 2004"    "Feb 27, 2004"   
##  [909] "Feb 29, 2004"    "Mar 2, 2004"     "Mar 10, 2004"    "Mar 12, 2004"   
##  [913] "Mar 13, 2004"    "Mar 14, 2004"    "Mar 16, 2004"    "Mar 19, 2004"   
##  [917] "Mar 21, 2004"    "Mar 24, 2004"    "Apr 18, 2004"    "Apr 20, 2004"   
##  [921] "Apr 22, 2004"    "Apr 25, 2004"    "Apr 27, 2004"    "Apr 29, 2004"   
##  [925] "May 1, 2004"     "May 2, 2004"     "May 5, 2004"     "May 15, 2004"   
##  [929] "May 16, 2004"    "May 19, 2004"    "May 25, 2004"    "May 27, 2004"   
##  [933] "May 29, 2004"    "Jun 27, 2004"    "Jun 29, 2004"    "Jul 1, 2004"    
##  [937] "Jul 3, 2004"     "Jul 4, 2004"     "Jul 6, 2004"     "Jul 10, 2004"   
##  [941] "Jul 16, 2004"    "Jul 17, 2004"    "Jul 18, 2004"    "Jul 21, 2004"   
##  [945] "Jul 23, 2004"    "Jul 25, 2004"    "Jul 27, 2004"    "Jul 29, 2004"   
##  [949] "Aug 1, 2004"     "Aug 20, 2004"    "Aug 21, 2004"    "Aug 22, 2004"   
##  [953] "Aug 25, 2004"    "Aug 28, 2004"    "Aug 31, 2004"    "Sep 1, 2004"    
##  [957] "Sep 3, 2004"     "Sep 4, 2004"     "Sep 5, 2004"     "Sep 10-11, 2004"
##  [961] "Sep 10, 2004"    "Sep 11, 2004"    "Sep 12, 2004"    "Sep 13, 2004"   
##  [965] "Sep 14, 2004"    "Sep 14-15, 2004" "Sep 15, 2004"    "Sep 16, 2004"   
##  [969] "Sep 17-18, 2004" "Sep 18-19, 2004" "Sep 19, 2004"    "Sep 21, 2004"   
##  [973] "Sep 22, 2004"    "Sep 25, 2004"    "Sep 30, 2004"    "Oct 3, 2004"    
##  [977] "Oct 6, 2004"     "Oct 9, 2004"     "Oct 14, 2004"    "Oct 16, 2004"   
##  [981] "Nov 2, 2004"     "Nov 5, 2004"     "Nov 7, 2004"     "Nov 13, 2004"   
##  [985] "Nov 28, 2004"    "Dec 1, 2004"     "Dec 4, 2004"     "Dec 5, 2004"    
##  [989] "Dec 8, 2004"     "Dec 23, 2004"    "Dec 26, 2004"    "Dec 27, 2004"   
##  [993] "Jan 10, 2005"    "Jan 14, 2005"    "Jan 16, 2005"    "Jan 19, 2005"   
##  [997] "Jan 20, 2005"    "Jan 23, 2005"    "Jan 24, 2005"    "Jan 26, 2005"   
## [1001] "Jan 28, 2005"    "Jan 29, 2005"    "Jan 30, 2005"    "Jan 31, 2005"   
## [1005] "Feb 1, 2005"     "Feb 2, 2005"     "Feb 4, 2005"     "Feb 6, 2005"    
## [1009] "Feb 9, 2005"     "Feb 13, 2005"    "Feb 19, 2005"    "Feb 22, 2005"   
## [1013] "Feb 25, 2005"    "Feb 26, 2005"    "Feb 27, 2005"    "Mar 1, 2005"    
## [1017] "Mar 2, 2005"     "Mar 5, 2005"     "Apr 2, 2005"     "Apr 5, 2005"    
## [1021] "Apr 9, 2005"     "Apr 12, 2005"    "Apr 15, 2005"    "Apr 17, 2005"   
## [1025] "May 7, 2005"     "May 8, 2005"     "May 11, 2005"    "May 14, 2005"   
## [1029] "May 15, 2005"    "May 18, 2005"    "May 21, 2005"    "May 22, 2005"   
## [1033] "Jun 16, 2005"    "Jun 18, 2005"    "Jun 19, 2005"    "Jun 21, 2005"   
## [1037] "Jun 23, 2005"    "Jun 25, 2005"    "Jun 26, 2005"    "Jun 30, 2005"   
## [1041] "Jul 2, 2005"     "Jul 7, 2005"     "Jul 10, 2005"    "Jul 12, 2005"   
## [1045] "Jul 30, 2005"    "Jul 31, 2005"    "Aug 2, 2005"     "Aug 3, 2005"    
## [1049] "Aug 6, 2005"     "Aug 7, 2005"     "Aug 9, 2005"     "Aug 17, 2005"   
## [1053] "Aug 20, 2005"    "Aug 21, 2005"    "Aug 24, 2005"    "Aug 26, 2005"   
## [1057] "Aug 29, 2005"    "Aug 31, 2005"    "Sep 2, 2005"     "Sep 4, 2005"    
## [1061] "Sep 6, 2005"     "Oct 5, 2005"     "Oct 7, 2005"     "Oct 9, 2005"    
## [1065] "Oct 23, 2005"    "Oct 25, 2005"    "Oct 28, 2005"    "Oct 30, 2005"   
## [1069] "Oct 31, 2005"    "Nov 3, 2005"     "Nov 6, 2005"     "Nov 9, 2005"    
## [1073] "Nov 12, 2005"    "Nov 16, 2005"    "Nov 19, 2005"    "Nov 25, 2005"   
## [1077] "Nov 28, 2005"    "Dec 3, 2005"     "Dec 7, 2005"     "Dec 10, 2005"   
## [1081] "Dec 12, 2005"    "Dec 15, 2005"    "Dec 19, 2005"    "Dec 21, 2005"   
## [1085] "Dec 31, 2005"

By looking at the unique data values –> this does not seem true as dates occur every year. Looking at the match IDs this seems to indicate that this data set includes all one day international matches from Jan 1st 1996 - Jan 26 2005.

Some descriptives:

Are teams more likely to win at home?

cricket$winathome <- ifelse(cricket$winner == cricket$ground_country, 1, 0)

table(cricket$winathome) #table counts how many of each value
## 
##   0   1 
## 785 452
#indicates it's not more common for teams to win at home (785 vs. 452)

This variable may be less important for T20 cricket. Often in test cricket teams are critiqued if they can’t win when they play away. However in ODIs it is part of the competition to play many games away from home.

We can use the ball_remaining column to indicate the “quickest” games

cricket %>% 
  select(match_id, ball_remaining, team1, team2) %>% 
  arrange(ball_remaining) #if ball remaining is a character how does arrange work? 
## # A tibble: 1,237 x 4
##    match_id   ball_remaining team1        team2       
##    <chr>      <chr>          <chr>        <chr>       
##  1 ODI # 1362 D/L method)    South Africa Sri Lanka   
##  2 ODI # 1390 D/L method)    West Indies  South Africa
##  3 ODI # 1485 D/L method)    Australia    Sri Lanka   
##  4 ODI # 1490 D/L method)    India        Sri Lanka   
##  5 ODI # 1626 D/L method)    South Africa Pakistan    
##  6 ODI # 1647 D/L method)    South Africa New Zealand 
##  7 ODI # 1663 D/L method)    Zimbabwe     New Zealand 
##  8 ODI # 1672 D/L method)    Australia    West Indies 
##  9 ODI # 1673 D/L method)    Sri Lanka    South Africa
## 10 ODI # 1676 D/L method)    West Indies  Zimbabwe    
## # … with 1,227 more rows

NOTE: The Duckworth–Lewis–Stern method (DLS OR D/L method) is a mathematical formulation designed to calculate the target score for the team batting second in a limited overs cricket match interrupted by weather or other circumstances.

We need to pull out the numbers from this column:

library(tidyr)

cricket %>% 
  select(match_id, ball_remaining, team1, team2) %>% 
  mutate(ball_no = extract_numeric(ball_remaining)) %>% #here I have used the extract_numeric function within mutate
  arrange(-ball_no)
## extract_numeric() is deprecated: please use readr::parse_number() instead
## # A tibble: 1,237 x 5
##    match_id   ball_remaining           team1                 team2       ball_no
##    <chr>      <chr>                    <chr>                 <chr>         <dbl>
##  1 ODI # 1776 with 274 balls remainin… Zimbabwe              Sri Lanka       274
##  2 ODI # 1958 with 272 balls remainin… Canada                Sri Lanka       272
##  3 ODI # 2172 with 253 balls remainin… United States of Ame… Australia       253
##  4 ODI # 2122 with 244 balls remainin… Zimbabwe              Sri Lanka       244
##  5 ODI # 1465 with 239 balls remainin… Scotland              West Indies     239
##  6 ODI # 1758 with 231 balls remainin… Kenya                 India           231
##  7 ODI # 1961 with 228 balls remainin… Bangladesh            South Afri…     228
##  8 ODI # 1940 with 226 balls remainin… England               Australia       226
##  9 ODI # 2063 with 217 balls remainin… England               Sri Lanka       217
## 10 ODI # 1858 with 206 balls remainin… Bangladesh            Sri Lanka       206
## # … with 1,227 more rows

//////////////////////////////////////////////

How can we summarise all this information - maybe a graph isn’t the most suitable

This data set provides us with a lot of information across many years and many games. When tasked with displaying this information - for a specific series/cup/tour/etc - a table may be more suitable for displaying this information

Source: https://github.com/tashapiro/TidyTuesday/blob/master/2021/W49/cricket_world_cup.R

#extra libraries 

library(dplyr)
library(gt)
library(gtExtras)
#library(ggflags)
library(paletteer)
library(systemfonts)

#remotes::install_github("jthomasmock/gtExtras")
#devtools::install_github("rensa/ggflags"
df <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-11-30/matches.csv')
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   .default = col_character(),
##   score_team1 = col_double(),
##   score_team2 = col_double(),
##   wickets_team1 = col_double(),
##   wickets_team2 = col_double(),
##   margin = col_double()
## )
## ℹ Use `spec()` for the full column specifications.
df$match_date<-as.Date(df$match_date,'%b %d, %Y')

#get info for team 1
t1<-df%>%select(team1, score_team1, wickets_team1, team2, winner, margin, series, match_date, match_id)%>%
rename(team = team1, score=score_team1, wickets=wickets_team1, opponent=team2)

#get info for team 2
t2<-df%>%select(team2, score_team2, wickets_team2, team1, winner, margin, series, match_date, match_id)%>%
  rename(team = team2, score=score_team2, wickets=wickets_team2, opponent=team1)

#combine team 1 and team 2 data, create vertical format for data
df_new<-rbind(t1,t2)
#create win indicator, if team name is the same as the winner name, then 1 (won), or 0 (lost)
df_new$win<-ifelse(df_new$team==df$winner,1,0)
#get data just for ICC World Cup 1999
df_1996<-df_new%>%filter(match_date>=as.Date("1999-05-14") & match_date<=as.Date("1999-06-20"))%>%
  group_by(team)%>%
  summarise(score=sum(score),
            wickets=sum(wickets),
            games=n(),
            avg_score=round(sum(score)/n(),0),
            wins=sum(win),
            losses=n()-sum(win),
            win_perc=round(sum(win)/n(),2))%>%
  #arrange data set based on wins
  arrange(desc(wins, win_perc))%>%
  #add flag images - images taken from https://www.flaticon.com/packs/countrys-flags
  mutate(
    flag = case_when(
      team == "Sri Lanka" ~ 'https://cdn-icons-png.flaticon.com/512/197/197398.png',
      team == "South Africa" ~ 'https://cdn-icons-png.flaticon.com/512/197/197562.png',
      team == "Pakistan" ~ 'https://cdn-icons-png.flaticon.com/512/197/197606.png',
      team == "India" ~ 'https://cdn-icons-png.flaticon.com/512/197/197419.png',
      team == "Australia" ~ 'https://cdn-icons-png.flaticon.com/512/197/197507.png',
      team == "Netherlands" ~'https://cdn-icons-png.flaticon.com/512/197/197441.png',
      team == "United Arab Emirates" ~'https://cdn-icons-png.flaticon.com/512/197/197569.png',
      team == "Kenya" ~'https://cdn-icons-png.flaticon.com/512/197/197608.png',
      team == "Zimbabwe" ~'https://cdn-icons-png.flaticon.com/512/197/197394.png',
      team == "England" ~'https://cdn-icons-png.flaticon.com/512/197/197485.png',
      team == "New Zealand" ~'https://cdn-icons-png.flaticon.com/512/197/197589.png',
      team == "West Indies" ~'https://s.ndtvimg.com/images/entities/300/west-indies-2119.png'
    ))%>%
  select(flag, everything())

#create list of scores
scores<-df_new%>%filter(match_date>=as.Date("1999-05-14") & match_date<=as.Date("1999-06-20"))%>%
  arrange(match_date)%>%group_by(team)%>%summarise(
  scores_data = list(score), .groups = "drop")
#create list of wins and losses
wins_losses<-df_new %>% 
filter(match_date>=as.Date("1999-05-14") & match_date<=as.Date("1999-06-20"))%>%
  arrange(match_date)%>%
  group_by(team) %>% 
  summarise(outcomes = list(win), .groups = "drop")%>%
  select(team,outcomes)

#merge data sets
df_1996<-left_join(df_1996,scores,by=c("team"="team"))
df_1996<-left_join(df_1996,wins_losses,by=c("team"="team"))

#create table
table<-df_1996%>%
  select(flag, team, score, wickets, games, wins, losses, avg_score, scores_data, outcomes, win_perc)%>%
  gt()%>%
  gt_img_rows(flag)%>%
  fmt_percent(columns = win_perc, decimals = 0)%>%
  gt_color_rows(win_perc, palette = "ggsci::blue_material")%>%
  gt_sparkline(scores_data,  line_color = "#505050")%>%
  gt_plt_winloss(outcomes, max_wins = 16)%>%
  gt_theme_espn()%>%
  cols_align(
    align = "center",
    columns = c(scores_data, flag, outcomes)
  )%>%
  tab_footnote("Outcomes represents wins (blue) and losses (red) for all games played",
               locations = cells_column_labels(columns = outcomes))%>%
  cols_label(
    flag = "",
    win_perc = "WIN %",
    score = "TOTAL PTS",
    scores_data = "PTS PER GAME",
    avg_score = "AVG PTS"
  )%>%
  tab_options(heading.title.font.size = 20)%>%
  tab_header(title = "ICC World Cup 1999",
             subtitle= "Outcomes summary by team from ICC World Cup")%>%
  tab_source_note("Data from ESPN | Table Graphic by @tanya_shapiro")
## Warning: Domain not specified, defaulting to observed range within each
## specified column.
table
ICC World Cup 1999
Outcomes summary by team from ICC World Cup
team TOTAL PTS wickets games wins losses AVG PTS PTS PER GAME outcomes1 WIN %
Australia 2155 56 10 7 3 216 133.0 70%
Pakistan 2240 77 10 6 4 224 132.0 60%
South Africa 2008 64 9 6 3 223 213.0 67%
New Zealand 1524 51 8 4 4 190 241.0 50%
England 682 16 4 3 1 170 168.0 75%
India 1887 45 7 3 4 270 251.0 43%
West Indies 723 28 5 3 2 145 110.0 60%
Zimbabwe 1462 53 7 3 4 209 123.0 43%
Bangladesh 884 45 5 2 3 177 223.0 40%
Sri Lanka 1003 44 5 2 3 201 275.0 40%
Kenya 1049 40 5 0 5 210 230.0 0%
Scotland 700 47 5 0 5 140 121.0 0%
Data from ESPN | Table Graphic by @tanya_shapiro

1 Outcomes represents wins (blue) and losses (red) for all games played

//////////////////////////////////////////////////////

Cricket_Who: Combining data sets which don’t go together

cricket_clean <- cricket %>% 
  select(team1, team2, winner, match_date) %>% 
  pivot_longer(cols = starts_with("team"), 
               names_to = "team",
               values_to = "country") %>% 
  filter(country == "England")

who_ep_clean <- who_ep %>% 
  select(first_aired, episode_number)

Only interested in the month

cricket_month <- cricket_clean %>% 
  mutate(month = (substr(cricket_clean$match_date, 1, 3))) %>% 
  mutate(month = recode_factor(month, "Jan" = "01", "Feb" = "02", "Mar" = "03", "Apr" = "04", "May" = "05", "Jun" = "06", "Jul" = "07", "Aug" = "08", "Sep" = "09", "Oct" = "10", "Nov" = "11", "Dec" = "12")) %>% 
  count(month)
doctor_month <- who_ep_clean %>% 
  separate(first_aired, into = c("year", "month", "day"), sep = "-") %>% 
  count(month)

let’s plot

cricket_who <- cricket_month %>% 
  ggplot(aes(x = month, y= n)) +
  geom_col(fill = "green", alpha = 0.5) + 
  geom_col(data = doctor_month, fill = "blue", alpha = 0.5)

cricket_who 

we can do better

cricket_month_2 <- cricket_month %>% 
  rename(n_cricket = n)
  

doctor_month_2 <- doctor_month %>% 
  rename(n_doctor = n)

cricket_doctor <- cricket_month_2 %>% 
  left_join(doctor_month_2) %>% 
  pivot_longer(cols = starts_with("n"),
               names_to = "category",
               values_to = "count") %>% 
  mutate(category = recode_factor(category, "n_cricket" = "cricket", "n_doctor" = "doctor"))
## Joining, by = "month"
cricket_doctor$month <- as.integer(cricket_doctor$month)

new plot

library(ggimage)
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
g <- cricket_doctor %>% 
  ggplot(aes(x = month, y = count)) +
  geom_line(size = 1.6,  aes(colour= category), show.legend = FALSE) +
  scale_colour_manual(values = c("#51BB27", "#003b6f")) +
  geom_image(mapping = aes(x = 1.2, y = 9, image = '~/Desktop/2021/VR_scholarship/Cricket_Who/tardis.png'), size = 0.25) +
  geom_image(mapping= aes(x = 1.2, y = 32, image = '~/Desktop/2021/VR_scholarship/Cricket_Who/ball.png'), size = 0.13) +
  theme(rect = element_rect(fill = "transparent")) +
  theme_bw() + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  scale_x_continuous(breaks = seq(1,12)) +
  labs(title= "Episodes vs. Games per month",
                      y="Number of episodes or games", x = "Month")
g

ggplotly(g) # interactive but no pics 
## Warning in geom2trace.default(dots[[1L]][[1L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_GeomImage() has yet to be implemented in plotly.
##   If you'd like to see this geom implemented,
##   Please open an issue with your example code at
##   https://github.com/ropensci/plotly/issues

## Warning in geom2trace.default(dots[[1L]][[1L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_GeomImage() has yet to be implemented in plotly.
##   If you'd like to see this geom implemented,
##   Please open an issue with your example code at
##   https://github.com/ropensci/plotly/issues